<#include "layout.html"/>
<@layout>
<h2 class="sub-header">
写文章
<span class="pull-right">
<button class="btn btn-default" type="submit" onclick="formSubmit('0')">暂存&nbsp;<span class="glyphicon glyphicon-floppy-disk"></button>
<button class="btn btn-default" type="submit" onclick="formSubmit('1')">发布&nbsp;<span class="glyphicon glyphicon-floppy-open"></button>
</span>
</h2>
<form id="artForm">
	<input type="hidden" id="artId" name="article.id" value='${article.id!}'/>
	<input type="hidden" id="finish" name="article.finish" value='${article.title!"0"}'/>
	<input type="text" id="title" class="form-control" placeholder="请输入文章标题" name="article.title" value='${article.title!""}'>
	<br/>
   	<div class="row">
   		<div class="col-md-6">
			<select class="form-control" name="article.projectId">
			<option value="">请选择类别</option>
			<#list projectList as project>
				<option value="${project.id}" <#if article.projectId??><#if article.projectId == project.id>selected="selected"</#if></#if> >${project.name}</option>
			</#list>
			</select>
		</div>
   		<div class="col-md-6">
			<input type="text" class="form-control" placeholder="请输入标签，多个以逗号分隔" name="article.tags" value='${article.tags!""}'>
		</div>
	</div>
	<br/>
	<input type="hidden" id="artTypeVal" name="article.type" value='${article.type!"0"}'/>
  	<div class="input-group">
      <div class="input-group-btn">
        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
        	<span id="artType">
        		<#if article.type??>
        			<#if article.type == 0>
        				原创
        			<#else>
        				转载
        			</#if>
        		<#else>
        			原创
        		</#if>
        	</span> 
        	<span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li><a href="javascript:;" onclick="setArtTypy(this)">原创</a></li>
          <li><a href="javascript:;" onclick="setArtTypy(this)">转载</a></li>
        </ul>
      </div><!-- /btn-group -->
      <input type="text" class="form-control" name="article.url" <#if article.type??><#if article.type == 0>disabled="disabled"</#if><#else>disabled="disabled"</#if> id="artUrl" placeholder="原文链接地址" value='${article.url!""}'>
    </div><!-- /input-group -->
    <br/>
	 <!-- 加载编辑器的容器 -->
	<script id="container" name="article.content" type="text/plain">
		${article.content!""}
	</script>
</form>
<div class="modal fade" id="msgModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
         <div class="alert alert-dismissable" id="alertMsg">
         	<button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
		   <span id="msg"></span>
         </div>
	</div><!-- /.modal -->
</div>
<!-- 配置文件 -->
<script type="text/javascript" src="${path}/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="${path}/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container');
    
    function setArtTypy(dom){
		if(dom.innerHTML == "原创"){
			$('#artTypeVal').val("0");
			$('#artUrl').val("");
			$('#artUrl').attr("disabled","disabled");
		}else{
			$('#artTypeVal').val("1");
			$('#artUrl').removeAttr("disabled");
		}
		$('#artType').html(dom.innerHTML);  
    }
    
    function formSubmit(finish){
    	var invokeURL;
    	if($("#artId").val() && $("#artId").val() != null){
    		invokeURL = "${path}/admin/article/editArticle.html";
    	}else{
    		invokeURL = "${path}/admin/article/addAtricle.html";
    	}
    	$('#finish').val(finish);
    	$.post(invokeURL,$("#artForm").serialize(),function(data){
    		$('#msg').html(data.msg);
    		if(data.success == true){
    			$('#alertMsg').removeClass("alert-danger");
    			$('#alertMsg').addClass("alert-success");
    		}else{
    			$('#alertMsg').removeClass("alert-success");
    			$('#alertMsg').addClass("alert-danger");
    		}
    		$('#msgModal').modal('show');
    	}, "json");
    }
    $('#msgModal').on('hide.bs.modal', function () {location.href="${path}/admin/article/";})
</script>
</@layout>
